package com.jeesite.modules.common;

import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class BusinessUtils {

    private static String AppID = "wxc86ac9d5537decf6";
    private static String AppSecret = "55ef33c909863b6fb1a1d27adca79f66";



    public static String getFrontServer(){
        return "http://h5.wangjianxin.top/";
    }
    public static String getImgFrontServer(){
        return "http://img.wangjianxin.top/";
    }
    public static String getInitFrontServer(){
        return "http://h5.wangjianxin.top/ShareInterim/";
    }

    public static String getWxIndexFrontServer(){
        return "http://api.wangjianxin.top/wx/OAuth/";
    }

    public static String getAccessToken(String appid,String appSecret){


        return getAccessTokenByWxAPI();
    }

    /**
     * 访问微信服务API获取access_token
     * @return
     */
    public static String getAccessTokenByWxAPI(){

        String getAccessTokenUrl = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid="+AppID+"" +
                "&secret="+AppSecret+"";
        String getAccessTokenResult =  PostUtils.getToUrl(getAccessTokenUrl);
        String access_token = "";
        if(null != getAccessTokenResult){
            JSONObject jsonObject = (JSONObject) JSONObject.parse(getAccessTokenResult);
            log.info("getAccessToken JSONObject = {}", jsonObject);
            //{"errcode":40013,"errmsg":"invalid appid"} 微信返回的错误实例
            //{"access_token":"ACCESS_TOKEN","expires_in":7200} 返回的成功实例
            access_token = (String) jsonObject.get("access_token");
            log.info("getAccessToken access_token = {}", access_token);

            //保存起来

        }

        return access_token;
    }
}
